﻿using RTW.Core.Ioc;
using RTW.Core.Repository;
using RTW.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RTW.Servers
{
    public class UserServers : BaseServers<SysUser>, IAutoInject
    {
        private readonly IRepositoryAsync<SysUser> SysUserRepository;
        public UserServers()
        {
            SysUserRepository = new DapperAsyncRepository<SysUser>();
        }


        public async Task<List<SysUser>> GetAllUsers()
        {
            return (await SysUserRepository.GetAllEnumerableAsync()).ToList();
        }

        public async Task<SysUser> GetUser(int? id)
        {
            return await SysUserRepository.GetByIdAsync(id);
        }


        /// <summary>
        /// 根据单位ID获取数据
        /// </summary>
        /// <param name="DWID"></param>
        /// <returns></returns>
        public async Task<List<SysUser>> GetUserWhere(int? DWID)
        {
            return (await SysUserRepository.SqlWithParams("select * from Sys_User  where DWID=:DWID", new { DWID = DWID })).ToList();
        }
        public async Task<List<SysUser>> GetUserIDWhere(int? YHID)
        {
            return (await SysUserRepository.SqlWithParams("select * from Sys_User  where YHID=:YHID", new { YHID = YHID })).ToList();
        }

        public async Task<bool> AnyByName(object name)
        {
            return await SysUserRepository.SqlWithParamsBool("select * from Sys_User  where YHMC=:YHMC", new { YHMC = name });
        }

        public async Task<bool> AnyByCode(string code)
        {
            return await SysUserRepository.SqlWithParamsBool("select * from Sys_User  where DWDM=:DWDM", new { DWDM = code });
        }

        public async Task<List<SysUser>> GetUserID(string yhmd)
        {
            return (await SysUserRepository.SqlWithParams("select  YHID from Sys_User where YHMC=:YHMC ", new { YHMC = yhmd })).ToList();
        }
    }
}
